草庐IT

HTTP 400 错误

全部标签

mysql - go mysql SELECT查询导致变量赋值错误

我是Go新手,正在尝试查询mysql数据库。我尝试了以下代码:rows,err:=db.QueryRow("SELECT*FROMt_users")但是运行gorunmain.go给出了这个错误:cannotassign1valuesto2variables但是我没有收到任何错误:rows,err:=db.Query("DESCRIBEt_user")为什么我的select语句会出错? 最佳答案 mkopriva的回应QueryRowreturnsonevalue,Queryreturnstwo

http - PUT 使用流和进度上传文件的字节范围

我刚开始使用Go,需要一些帮助。我想从文件上传一定范围的字节。我已经通过将字节读入缓冲区来完成此操作。但这会增加内存使用量。我不想将字节读入内存,而是想在上传时流式传输它们并获得上传进度。我在Node.js中做了类似的事情,但很难为Go拼凑拼图。我现在拥有的代码如下所示:funcuploadChunk(id,mimeType,uploadURL,filePathstring,offset,sizeuint){//openfilefile,err:=os.Open(filePath)panicCheck(err,ErrorFileRead)//customerrorhandlerdefe

go - 如何使用返回自身以进行链接的方法为复杂的 http 客户端(如 gorequest)编写接口(interface)

我正在编写一个包,它需要将*gorequest.SuperAgent的实例传递给子包中的方法//main.gofuncmain(){req:=gorequest.New()result:=subpackage.Method(req)fmt.Println(result)}//subpackage.gofuncMethod(req*gorequest.SuperAgent)string{req.Get("http://www.foo.com").Set("bar","baz")_,body,_:=req.End()returnbody}我一直在兜圈子试图为gorequestsuperag

http - 由于来自服务器的 mime 不正确,无法使用 Go 打开 Zip

我有一个向服务器发送zip文件的应用程序。然后对zip进行操作,并在响应中发回一个新的zip。问题是发回的响应有application/octet-stream而不是application/zip消息的mime。我认为这就是为什么archive/zip无法打开生成的zip并且我得到一个zip:notavalidzipfile的原因。在检索zip文件时,我有什么办法可以更改mime吗?我获取zip的代码:funcGetZipFromServer(zipnamestring){//////////////////////////////////////////////////////Ope

docker - docker 内部的 Golang 错误

在构建我的go应用程序时,我在docker中遇到了一个奇怪的错误:./main.go:31:9:cannotusedb(type*"github.com/khwerhahn/somerepo/vendor/github.com/jinzhu/gorm".DB)astype*"app/vendor/github.com/jinzhu/gorm".DBinargumenttoMigrateThecommand'/bin/sh-cgo-wrapperinstall'returnedanon-zerocode:2有人可以向我提示正确的方向吗,因为该应用程序在本地运行得很好。它就在docker容

google-app-engine - 当代码在本地开发服务器上工作时,为什么 GAE 返回服务器错误?

我正在尝试使用GoogleAppEngine测试数据存储功能,我的代码在本地开发服务器中按预期工作://codebasedonthefollowingguide:https://cloud.google.com/datastore/docs/reference/libraries#client-libraries-install-gopackagedatastoretestimport("fmt""log""net/http""cloud.google.com/go/datastore""google.golang.org/appengine")typeTaskstruct{Descr

go - 计数返回错误结果

我有一个用户模型,目前只有一行。我正在尝试计算整个用户表的行数,这是我的代码:varcountint64db.Model(&models.User{}).Count(count)fmt.Println(count)我期待1但它正在打印0。使用gorm打印表格行数的正确方法是什么?更新:我的用户模型:packagemodelsimport"github.com/jinzhu/gorm"typeUserstruct{gorm.ModelNamestringPasswordstringAdminbool} 最佳答案 您需要将count变量

Golang GRPC 返回 EOF 错误

我正在使用http通过以下代码调用RPCfunc(c*CallClient)Wallet(methodstring,req,repinterface{})error{client:=&http.Client{}data,_:=EncodeClientRequest(method,req)reqest,_:=http.NewRequest("POST",c.endpoint,bytes.NewBuffer(data))resp,err:=client.Do(reqest)iferr!=nil{returnerr}deferresp.Body.Close()io.Copy(ioutil.D

mongodb - 在 http 中输出一个 .mp4 文件,从数据库中提取到浏览器

已回答我在使用Mongodb和Gridfs时遇到了困难,将其与Go的http包一起使用。我正在尝试将一个.mp4文件存储到Gridfs中,然后将其拉出到浏览器中进行播放。HereswhatIamdoingnow.Itsuccessfullypullsthefilefromdatabase,Icouldevenwriteitcorrectlytoadownloadlocation.//Connecttodatabase//Sessiontodatabasefuncmovie(whttp.ResponseWriterr*http.Request){file,err:=db.GridFS("

go - 从 postman 检查时获取 404 页面未找到错误

我正在使用goappserve运行以下代码。从postman检查时,以某种方式出现404找不到页面错误。你能帮我解决这个问题吗packagehelloimport("fmt""net/http""github.com/julienschmidt/httprouter")funcIndex(whttp.ResponseWriter,r*http.Request,_httprouter.Params){fmt.Fprint(w,"Welcome!\n")}funcHello(whttp.ResponseWriter,r*http.Request,pshttprouter.Params){f